"""
通用评论模型
"""
from typing import Optional
from datetime import datetime
from pydantic import BaseModel, Field


class CommentBase(BaseModel):
    """评论基础模型"""
    content: str = Field(..., min_length=1, max_length=2000, description="评论内容")


class CommentCreate(CommentBase):
    """创建评论模型"""
    parent_comment_id: Optional[str] = Field(None, description="父评论ID，用于回复功能")
    status: Optional[str] = Field(None, description="评论状态（动态状态，默认为已发布）")


class CommentUpdate(BaseModel):
    """更新评论模型"""
    content: Optional[str] = Field(None, min_length=1, max_length=2000, description="评论内容")
    status: Optional[str] = Field(None, description="评论状态（动态状态）")
    is_deleted: Optional[bool] = Field(None, description="是否已删除（保持向后兼容）")


class Comment(CommentBase):
    """评论响应模型"""
    id: str = Field(..., description="评论ID")
    author_id: str = Field(..., description="作者ID")
    author_name: str = Field(..., description="作者名称")
    parent_comment_id: Optional[str] = Field(None, description="父评论ID，用于回复")
    status: str = Field(default="published", description="评论状态（动态状态）")
    is_deleted: bool = Field(default=False, description="是否已删除（保持向后兼容）")
    created_at: datetime = Field(default_factory=datetime.utcnow, description="创建时间")
    updated_at: Optional[datetime] = Field(None, description="更新时间")
    deleted_at: Optional[datetime] = Field(None, description="删除时间")


class CommentInDB(Comment):
    """数据库中的评论模型"""
    # 可以添加数据库特定字段
    pass
